//
//  ALAlertView.swift
//  DemoNavBar
//
//  Created by YangHuan on 2019/12/13.
//  Copyright © 2019 YangHuan. All rights reserved.
//

import UIKit
import AEAlertView

class ALAlertView: AEAlertView {
    
    public class func cancel(title: String, message: String, actions: [String], handler:((AEAlertAction)->Void)?) {
        
        let view = ALAlertView(style: .defaulted, title: title, message: message)

        let cancel = AEAlertAction(title: actions[0], style: .cancel) { (cancel) in
            view.dismiss()
        }
        view.addAction(action: cancel)
        
        if actions.count > 1 {
            let def = AEAlertAction(title: actions[1], style: .defaulted) { (action) in
                if handler != nil {
                    handler!(action)
                }
                view.dismiss()
            }
            view.addAction(action: def)
        }
        view.show()
    }
    
    public class func alert(title: String, message: String, actions: [String], handler:((AEAlertAction)->Void)?) {
        
        let view = ALAlertView(style: .defaulted, title: title, message: message)

        let def = AEAlertAction(title: actions[0], style: .defaulted) { (action) in
            if handler != nil {
                handler!(action)
            }
            view.dismiss()
        }
        view.addAction(action: def)
        view.show()
    }
    
    convenience init() {
        
        self.init(style: .defaulted, title: nil, message: nil)
    }
    
    override init(style alertViewStyle: AEAlertViewStyle, title: String?, message: String?) {
        
        super.init(style: alertViewStyle, title: title, message: message)
        
        titleColor = UIColor.darkGray
        messageColor = UIColor.darkGray
        
        buttonColor = UIColor(red: 253/255.0, green: 101/255.0, blue: 141/255.0, alpha: 1.0)
        buttonTitleColor = UIColor.white
        buttonLayerBorderColor = nil
        
        cancelButtonColor = UIColor(red: 178/255.0 , green: 171/255.0, blue: 226/255.0, alpha: 1.0)
        cancelButtonTitleColor = UIColor.white
        cancelButtonLayerBorderColor = nil
         
       actionCornerRadius = 20
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
}
